package ferp.center.server.entity;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import ferp.center.network.RequestWhistAdd;
import ferp.core.card.Card;

import javax.persistence.*;
import java.util.Date;

/**
 * User: igorgok
 * Date: 12/5/12 9:53 AM
 */

@Entity
public class Whist
{
/*
  public Key getKey() {return key;}
  public Profile getProfile(EntityManager em) {return em.find(Profile.class, profile);}
  public void setProfile(long id) {this.profile = KeyFactory.createKey("Profile", id);}
  public void setProfile(Profile profile) {this.profile = profile.getKey();}
  public void setCreated(Date date) {this.created = date;}
*/

  public int getHand() {return hand;}
  public int getCards() {return cards;}
  public int getTricks() {return cards;}
  public Card.Suit getSuit() {return Card.Suit.valueOf(suit);}
  public char getResult() {return result;}

  public Whist() {}
  public Whist(RequestWhistAdd rwa)
  {
    profile = KeyFactory.createKey(Profile.class.getSimpleName(), rwa.profile);
    configuration = rwa.configuration;
    created = new Date();
    hand = rwa.hand;
    cards = rwa.cards;
    tricks = rwa.tricks;
    suit = rwa.trump.shortName();
    result = rwa.result;
    pool = rwa.pool;
    score = rwa.score;
  }

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Key key;
  // profile
  private Key profile;
  // configuration
  private String configuration;
  // player's accumulated pool
  private long pool;
  // player's accumulated score
  private long score;
  // creation date
  @Temporal(TemporalType.DATE)
  private Date created;
  // hand in game
  private int hand;
  // cards in hand
  private int cards;
  // contract tricks
  private int tricks;
  // contruct suit
  private String suit;
  // bid result
  private char result;

  @Version
  private int version;
}
